package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
@ToString
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties("handler")
//日报文章管理
public class DailyDetail extends BaseDomain{
    public static final Integer STATE_HEADLINE = 1; //头条
    public static final Integer STATE_RECOMMEND = 2; //推荐
    public static final Integer STATE_COMMON = 3; //普通
    public static final Integer STATE_FORBIDDEN = 4; //禁用


    private String title;//文章标题

    private Date createTime;//创建时间

    private Date releaseTime;//发布时间

    private Integer sequence;//序列

    private DailyCatalog catalog;//日报分类

    private String coverUrl;//封面

    private DailyContent dailyContent;//文章内容

    private Integer state=STATE_COMMON;//状态默认为普通

    public String getStateName() {
        String msg = "普通";
        if (state == STATE_HEADLINE) {
            msg = "头条";
        }else if(state==STATE_RECOMMEND){
            msg = "推荐";
        }else if (state==STATE_FORBIDDEN){
            msg="禁用";
        }
        return msg;
    }

    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("sequence", sequence);
        map.put("coverUrl", coverUrl);
        map.put("state", state);
        if (catalog != null) {
            map.put("dailyId", catalog.getDailyId());
            map.put("catalogId", catalog.getId());
        }
        return JSONUtil.toJSONString(map);
    }


}